/**
 * Copyright (c) 2018 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package com.evaluationSystem.controller;

import com.evaluationSystem.annotation.LogOperation;
import com.evaluationSystem.config.R;
import com.evaluationSystem.entity.DictType;
import com.evaluationSystem.entity.dto.SysDictTypeDTO;
import com.evaluationSystem.service.SysDictTypeService;
import com.evaluationSystem.util.AssertUtils;
import com.evaluationSystem.util.PageData;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 字典类型
 *
 * @author Mark sunlightcs@gmail.com
 */
@RestController
@RequestMapping("sys/dict/type")
public class SysDictTypeController {
    @Autowired
    private SysDictTypeService sysDictTypeService;

    @GetMapping("page")
    @RequiresPermissions("sys:dict:page")
    public R<PageData<SysDictTypeDTO>> page(@RequestParam Map<String, Object> params){
        //字典类型
        PageData<SysDictTypeDTO> page = sysDictTypeService.page(params);

        return R.success(page);
    }

    @GetMapping("list")
    public R<List<SysDictTypeDTO>> list(@RequestParam Map<String, Object> params){
        //字典类型
        List<SysDictTypeDTO> list = sysDictTypeService.list(params);

        return R.success(list);
    }

    @GetMapping("{id}")
    @RequiresPermissions("sys:dict:info")
    public R<SysDictTypeDTO> get(@PathVariable("id") Long id){
        SysDictTypeDTO data = sysDictTypeService.get(id);

        return R.success(data);
    }

    @PostMapping
    @LogOperation("保存")
    @RequiresPermissions("sys:dict:save")
    public R save(@RequestBody SysDictTypeDTO dto){

        sysDictTypeService.save(dto);

        return R.success();
    }

    @PutMapping
    @LogOperation("修改")
    @RequiresPermissions("sys:dict:update")
    public R update(@RequestBody SysDictTypeDTO dto){

        sysDictTypeService.update(dto);

        return R.success();
    }

    @DeleteMapping
    @LogOperation("删除")
    @RequiresPermissions("sys:dict:delete")
    public R delete(@RequestBody Long[] ids){
        //效验数据
        AssertUtils.isArrayEmpty(ids, "id");

        sysDictTypeService.delete(ids);

        return R.success();
    }

    @GetMapping("all")
    public R<List<DictType>> all(){
        List<DictType> list = sysDictTypeService.getAllList();

        return R.success(list);
    }

}